{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b43cfb70",
   "metadata": {},
   "source": [
    "* 记录人：廖洪恩\n",
    "* 记录时间：2022年6月29日\n",
    "* 记录内容：菜品识别\n",
    "* 参考文档：https://console.faceplusplus.com.cn/documents/4888391"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "148ca3b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.4d003112537b673dbf7678e9ab2e9fc4.315360000.1971871359.282335-25863392', 'expires_in': 2592000, 'session_key': '9mzdWulMP5xzaf3GOJGnEDoJ9MPpbvZqZbzkkUv4McdnHkOaK7jlzKvYdhUYBNb0XCXhF5oGeLIfgvionpsAVZUynjeLzg==', 'access_token': '24.a54fe9409265312a9ccbfc37ad7709b8.2592000.1659103359.282335-25863392', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'c7eef7207e21e48de8ba93ec459e5925'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload ={\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'GLTKUukmReM3i4KZFvrPSIdl',\n",
    "    'client_secret':'PwbscXSfn2LPqgxTGsO0wdnRZLzGe5dV'\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "49de5bb5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.a54fe9409265312a9ccbfc37ad7709b8.2592000.1659103359.282335-25863392'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Hongen_AI=response.json()['access_token']\n",
    "Hongen_AI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "358d45ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result_num': 5, 'result': [{'name': '牛排', 'calorie': '125', 'probability': '0.931617', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E7%89%9B%E6%8E%92/1156436', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/a044ad345982b2b7d0a2b2eba9e2dcef76094b362dc6', 'description': '牛排，或称牛扒，是片状的牛肉，是西餐中常见的食物之一。牛排的烹调方法以煎和烤制为主。欧洲中世纪时，猪肉及羊肉是平民百姓的食用肉，牛肉则是王公贵族们的高级肉品，尊贵的牛肉被他们搭配上了当时也是享有尊贵身份的胡椒粉及香辛料一起烹调，并在特殊场合中供应，以彰显主人的尊贵身份。清末小说中已出现[牛排]、[猪排]等西菜菜名，可能是因形似上海[大排](猪丁骨)，故名[排]。而在上海方言里，[排]发[ba]音，广州话又作牛扒。'}, 'has_calorie': True}, {'name': '沙朗牛排', 'probability': '0.048552', 'baike_info': {}, 'has_calorie': False}, {'name': '牛排套餐', 'calorie': '177', 'probability': '0.00796423', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E7%89%9B%E6%8E%92%E5%A5%97%E9%A4%90/3952704', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/838ba61ea8d3fd1fddad9e353e4e251f95ca5f1c', 'description': '牛排套餐，是指牛排、素菜、萝卜、煎蛋、意大利通心粉等食物结合在一起的西式套餐，味道可口诱人，有多种款式可供选择。'}, 'has_calorie': True}, {'name': 'T骨牛排', 'probability': '0.00551319', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/T%E9%AA%A8%E7%89%9B%E6%8E%92/6805193', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/c75c10385343fbf2def67a7ebe7eca8064388f91', 'description': 'T骨牛排(T-bone steak)一般位于牛的上腰部，是一块由脊肉、脊骨,里脊肉等构成的大块牛排。美式T骨牛排(porterhouse steak)形状同T骨牛排，但较T骨牛排大些，一般厚3厘米左右，重450克左右。T骨牛排一般厚2厘米左右，重约300克，小点的200克，厚度1.7厘米。其加工方法是：首先包装袋和多余的脂肪，脂肪要保留一点增加香味，然后按规定的厚度和重量切开外脊肉和里脊肉，最后用锯将脊骨锯断成厚片状即可。'}, 'has_calorie': False}, {'name': '铁板肥牛', 'calorie': '125', 'probability': '0.00146076', 'baike_info': {}, 'has_calorie': True}], 'log_id': 1542146733063340608}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "菜品识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/dish\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('niupai.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "access_token = '24.a54fe9409265312a9ccbfc37ad7709b8.2592000.1659103359.282335-25863392'\n",
    "payload={\n",
    "    'access_token':'24.a54fe9409265312a9ccbfc37ad7709b8.2592000.1659103359.282335-25863392',\n",
    "    'image':img,\n",
    "    'baike_num':5,\n",
    "    \"top_num\":5\n",
    "}\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2807e51f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
